import { getAreaObj } from '@/utils/util'

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '服务组织所在地区',
			prop: 'unitAreas',
			propName: 'unitAreasName',
			regionGrade: 3,
			checkStrictly: false,
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '工单编号',
			prop: 'orderNo',
			span: 8,
		},
		{
			label: '服务组织名称',
			prop: 'organizationName',
			span: 8,
		},
		{
			label: '服务对象姓名',
			prop: 'elderlyName',
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'elderlyPhone',
			span: 8,
		},
		{
			label: '服务对象身份证号',
			prop: 'elderlyIdCard',
			span: 8,
		},
		{
			label: '助餐类型',
			prop: 'orderType',
			type: 'select',
			dicData: [
				{ label: '堂食', value: 0 },
				{ label: '配送', value: 1 },
				{ label: '助餐堂食', value: 2 },
			],
			span: 8,
		},
		{
			label: '助餐时间',
			prop: 'createTimeBetween',
			type: 'dateBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
		{
			label: '结算人/配送人',
			prop: 'staffName',
			type: 'input',
			span: 8,
		},
	],
}

export const detailConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '服务组织所在地区',
			prop: 'orgAreaName',
			span: 8,
		},
		{
			label: '服务组织名称',
			prop: 'organizationName',
			span: 8,
		},
		{
			label: '配送工单编号',
			prop: 'orderNo',
			span: 8,
		},
		{
			label: '服务对象姓名',
			prop: 'elderlyName',
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'elderlyPhone',
			span: 8,
		},
		{
			label: '服务对象身份证号',
			prop: 'elderlyIdCard',
			span: 8,
		},
		{
			label: '助餐时间',
			prop: 'endTime',
			span: 8,
		},
		{
			label: '助餐类型',
			prop: 'orderType',
			type: 'select',
			dicData: [
				{ label: '堂食', value: 0 },
				{ label: '配送', value: 1 },
				{ label: '助餐堂食', value: 2 },
			],
			span: 8,
		},
		{
			label: '结算人/配送人',
			prop: 'staffName',
			span: 8,
		},
		{
			label: '配送地址',
			prop: 'address',
			span: 8,
		},
		{
			label: '菜品/套餐名称',
			prop: 'subItemNames',
			span: 8,
		},
		{
			label: '价格/元',
			prop: 'shouldAmount',
			span: 8,
		},
		{
			label: '送达照片',
			prop: 'middleServicePic',
			custome: 'file',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '服务组织所在地区', prop: 'orgAreaName', width: 100 },
		{ label: '助餐工单编号', prop: 'orderNo', width: 250 },
		{ label: '服务组织名称', prop: 'organizationName', width: 200 },
		{ label: '服务对象', prop: 'elderlyName', width: 120 },
		{ label: '证件号码', prop: 'elderlyIdCard', plusXing: '2,2', width: 120 },
		{ label: '联系方式', prop: 'elderlyPhone', width: 120 },
		{ label: '菜品/套餐名称', prop: 'subItemNames', width: 140 },
		{
			label: '助餐类型',
			prop: 'orderType',
			custome: 'tag',
			dicData: [
				{ label: '堂食', value: 0, type: 'success' },
				{ label: '配送', value: 1, type: 'primary' },
				{ label: '助餐堂食', value: 2, type: 'warning' },
			],
		},
		{ label: '订餐时间', prop: 'createTime', width: 140 },
		{ label: '助餐时间', prop: 'endTime', width: 100 },
		{ label: '结算人/配送人', prop: 'staffName', width: 140 },
		{ label: '配送地址', prop: 'address', width: 120 },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_omReposOrder_page',
	export: 'view_omReposOrder_export',
	delete: 'view_omReposOrder_del',
	detail: 'view_omReposOrder_detail',
}
export const auth = {
	...api,
	mulitSet: 'mulitSet',
}

export const baseConfig = {
	pageName: '助餐工单',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'orderNo',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	beforeOnLoadFormate: async (params) => {
		if (params.unitAreasName) {
			const tempArea = params.unitAreasName.split('/')
			params.orgAreaName = tempArea[tempArea.length - 1]
		}
		const queryObj = {
			...params,
			unitAreas: undefined,
			unitAreasName: undefined,
		}
		return Promise.resolve(queryObj)
	},
	operateFormate: async (row, type) => {
		return new Promise((resolve, reject) => {
			const middleServicePic = row.omReposOrderExtend?.middleServicePic
			resolve({
				...row,
				middleServicePic,
			})
		})
	},
	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	tableConfig,
	detailConfig,
}
